<template>
    <div class="login">
        <div class="login-container">
            <div class="left">

            </div>
            <div class="right">
                <div class="login-box">
                    <div class="title">
                        <h4>登录</h4>
                    </div>
                    <el-form ref="ruleFormRef" :model="ruleForm" :rules="rules" label-width="auto" class="demo-ruleForm"
                        status-icon>
                        <el-form-item prop="username">
                            <el-input v-model="ruleForm.username" />
                        </el-form-item>
                        <el-form-item prop="password">
                            <el-input v-model="ruleForm.password" />
                        </el-form-item>
                        <el-form-item>
                            <div style="width:100%">
                                <el-checkbox name="remember">
                                    记住我
                                </el-checkbox>
                                <span class="forget fr">忘记密码</span>
                            </div>
                        </el-form-item>
                        <el-form-item>
                            <el-button type="primary" @click="submitForm(ruleFormRef)" style="width: 100%;">
                                登录
                            </el-button>
                        </el-form-item>
                    </el-form>
                </div>
            </div>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { reactive, ref } from 'vue'
import type { FormInstance, FormRules } from 'element-plus'

interface RuleForm {
    username: string
    password: string
}

const remember = ref(false)

const ruleForm = reactive<RuleForm>({
    username: '',
    password: '',

})
const ruleFormRef = ref<FormInstance>()
const rules = reactive<FormRules<RuleForm>>({
    username: [
        { required: true, message: 'Please input Activity name', trigger: 'blur' },
        { min: 3, max: 10, message: 'Length should be 3 to 10', trigger: 'blur' },
    ],
    password: [
        { required: true, message: 'Please input Activity name', trigger: 'blur' },
        { min: 8, max: 16, message: 'Length should be 8 to 16', trigger: 'blur' },
    ],

})

const submitForm = async (formEl: FormInstance | undefined) => {
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            console.log('submit!')
        } else {
            console.log('error submit!', fields)
        }
    })
}
</script>

<style scoped lang="scss">
.login {
    .login-container {
        display: flex;
        align-items: center;
        width: 100%;
        height: 100vh;

        .left {
            flex: 1;
            height: 100%;
            background-color: #4d8cf1;
        }

        .right {
            // width: 600px;
            padding: 60px 100px;

            .login-box {
                width: 300px;
            }
        }
    }
}
</style>